package
{
	import component.button.MyButton;
	import component.timeline.MyTimeline;
	import component.tween.MyTween;
	
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.MouseEvent;
	
	import obecto.core.FLApplication;
	import obecto.event.FLEvent;

	[SWF(backgroundColor="0xCDCDCD")]
	public class TweenSample extends FLApplication
	{
		private var myTween : MyTween;
		
		private var startButton : MyButton;
		private var interruptButton : MyButton;
		private var reverseButton : MyButton;
		private var forwardButton : MyButton;
		private var endButton : MyButton;
		private var rollbackButton : MyButton;
		
		
		public function TweenSample()
		{
			super();
			
			stage.frameRate = 35;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			
			myTween = new MyTween();
			myTween.addEventListener(FLEvent.CREATION_COMPLETE, handleTweenCreationComplete);
			
			startButton = new MyButton();
			startButton.addEventListener(FLEvent.CREATION_COMPLETE, handleButtonCreationComplete);
			startButton.addEventListener(MouseEvent.CLICK, handleButtonClick);
			
			interruptButton = new MyButton();
			interruptButton.addEventListener(FLEvent.CREATION_COMPLETE, handleInterruptButtonCreationComplete);
			interruptButton.addEventListener(MouseEvent.CLICK, handleInterruptButtonClick);
			
			reverseButton = new MyButton();
			reverseButton.addEventListener(FLEvent.CREATION_COMPLETE, handleReverseButtonCreationComplete);
			reverseButton.addEventListener(MouseEvent.CLICK, handleReverseButtonClick);
			
			forwardButton = new MyButton();
			forwardButton.addEventListener(FLEvent.CREATION_COMPLETE, handleForwardButtonCreationComplete);
			forwardButton.addEventListener(MouseEvent.CLICK, handleForwardButtonClick);
			
			endButton = new MyButton();
			endButton.addEventListener(FLEvent.CREATION_COMPLETE, handleEndButtonCreationComplete);
			endButton.addEventListener(MouseEvent.CLICK, handleEndButtonClick);
			
			rollbackButton = new MyButton();
			rollbackButton.addEventListener(FLEvent.CREATION_COMPLETE, handleRollbackButtonCreationComplete);
			rollbackButton.addEventListener(MouseEvent.CLICK, handleRollbackButtonClick);
		}
		
		private function handleTweenCreationComplete(e : FLEvent) : void 
		{
			myTween.x = 100;
			myTween.y = 50;
			
			addChild(myTween);
		}
		
		private function handleButtonCreationComplete(e : FLEvent) : void 
		{
			startButton.x = 100;
			startButton.y = 350;
			
			startButton.label = "Start";
			startButton.textField.textColor = startButton.textColor;
			
			addChild(startButton);
		}
		
		private function handleInterruptButtonCreationComplete(e : FLEvent) : void 
		{
			interruptButton.x = 320;
			interruptButton.y = 350;
			
			interruptButton.label = "Interrupt";
			interruptButton.textField.textColor = interruptButton.textColor;
			
			addChild(interruptButton);
		}
		
		private function handleReverseButtonCreationComplete(e : FLEvent) : void 
		{
			reverseButton.x = 540;
			reverseButton.y = 350;
			
			reverseButton.label = "Reverse";
			reverseButton.textField.textColor = reverseButton.textColor;
			
			addChild(reverseButton);
		}
		
		private function handleForwardButtonCreationComplete(e : FLEvent) : void 
		{
			forwardButton.x = 540;
			forwardButton.y = 410;
			
			forwardButton.label = "Forward";
			forwardButton.textField.textColor = forwardButton.textColor;
			
			addChild(forwardButton);
		}
		
		private function handleEndButtonCreationComplete(e : FLEvent) : void 
		{
			endButton.x = 320;
			endButton.y = 410;
			
			endButton.label = "End";
			endButton.textField.textColor = endButton.textColor;
			
			addChild(endButton);
		}
		
		private function handleRollbackButtonCreationComplete(e : FLEvent) : void 
		{
			rollbackButton.x = 320;
			rollbackButton.y = 470;
			
			rollbackButton.label = "Rollback";
			rollbackButton.textField.textColor = rollbackButton.textColor;
			
			addChild(rollbackButton);
		}
		
		private function handleButtonClick(e : MouseEvent) : void 
		{
			myTween.tween.start();
		}
		
		private function handleInterruptButtonClick(e : MouseEvent) : void 
		{
			myTween.tween.interrupt();
		}
		
		private function handleReverseButtonClick(e : MouseEvent) : void 
		{
			myTween.tween.reverse();
		}
		
		private function handleForwardButtonClick(e : MouseEvent) : void 
		{
			myTween.tween.forward();
		}
		
		private function handleEndButtonClick(e : MouseEvent) : void 
		{
			myTween.tween.end();
		}
		
		private function handleRollbackButtonClick(e : MouseEvent) : void 
		{
			myTween.tween.rollback();
		}
		
	}
}